#!/bin/bash

# ============================================
# 检查 Nginx 配置干扰问题
# ============================================

echo "=== 检查 Nginx 主配置文件 ==="
grep -A 10 "server {" /etc/nginx/nginx.conf | head -20

echo ""
echo "=== 检查所有 server 块 ==="
sudo nginx -T 2>/dev/null | grep -B 5 -A 15 "server_name" | head -40

echo ""
echo "=== 检查是否有默认 server 块 ==="
sudo nginx -T 2>/dev/null | grep -B 5 -A 10 "default_server\|server_name _"

echo ""
echo "=== 检查所有配置文件 ==="
ls -la /etc/nginx/conf.d/
ls -la /etc/nginx/sites-enabled/ 2>/dev/null || echo "sites-enabled 不存在"

echo ""
echo "=== 检查 frontend.conf 的完整内容 ==="
cat /etc/nginx/conf.d/frontend.conf

echo ""
echo "=== 测试不同的路径 ==="
echo "测试 /api/login/ (应该匹配 location /api/):"
curl -s -o /dev/null -w "HTTP: %{http_code}\n" http://127.0.0.1/api/login/

echo ""
echo "测试 /api/init/settings/:"
curl -s -o /dev/null -w "HTTP: %{http_code}\n" http://127.0.0.1/api/init/settings/

echo ""
echo "=== 查看 Nginx 错误日志（实时） ==="
echo "请尝试访问一次，然后查看日志："
sudo tail -5 /var/log/nginx/frontend_error.log

